package com.youkeda.yunmusic.web.control;


import com.youkeda.yunmusic.web.model.Comment;
import com.youkeda.yunmusic.web.model.SongInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
public class SongInfoControl {

    private static Map<String,SongInfo> songInfoMap = new HashMap<>();

    @Autowired
    private  CommentPostControl commentPostControl;

    @RequestMapping(value = "/songinfo")
    public String index(String songId , ModelMap modelMap) {
       if(songId == null){
           songId = "35847388";
       }
       SongInfo songInfo = songInfoMap.get(songId);
       modelMap.addAttribute("song",songInfo);

        List<Comment> comments = commentPostControl.getComments(songId);
        modelMap.addAttribute("comments",comments);

        return "index";
    }

    @RequestMapping(value = "/songinfo/get")
    @ResponseBody
    //返回json api
    public SongInfo get(String songId){
        SongInfo songInfo = songInfoMap.get(songId);
        return songInfo;
    }

    @PostConstruct
    public void init(){
        //hello这首歌
        SongInfo songInfo = new SongInfo();
        songInfo.setId("35847388");
        songInfo.setName("Hello");
        songInfo.setSinger("Barbara Opsomer");
        songInfo.setAlbumName("Hello");
        songInfo.setCommentCount(20000);
        songInfo.setAlbumImg("http://p2.music.126.net/5HCFPM6iZDgxJd9TBGdOPQ==/7960464186183958.jpg?param=130y130");
        songInfo.setLyrics("La lueur des regards s'éteint sur le bitume" + "<br/>"
                + "我的眼泪夺眶而出 <br/> " +
                "Je suis accompagnée d'une certaine amertume" + "<br>"
                + "我心里感到一丝丝苦涩");
        songInfoMap.put("35847388",songInfo);


        songInfo  = new SongInfo();
        songInfo.setId("574566207");
        songInfo.setName("盗将行");
        songInfo.setSinger("花粥/马雨阳");
        songInfo.setAlbumName("粥请客（二）");
        songInfo.setCommentCount(63888);
        songInfo.setAlbumImg("http://p1.music.126.net/-qHPT3rhxDlu5zQV9NcQ-A==/109951163555860423.jpg?param=130y130");
        songInfo.setLyrics("劫过九重城关\n" + "<br>" +
                "我座下马正酣\n" +  "<br>" +
                "看那轻飘飘的衣摆\n" +  "<br>" +
                "趁擦肩把裙掀\n" +  "<br>" +
                "踏遍三江六岸\n" +  "<br>" +
                "借刀光做船帆\n" +  "<br>" +
                "任露水浸透了短衫\n" +  "<br>" +
                "大盗睥睨四野\n" +   "<br>" +
                "枕风宿雪多年\n" +   "<br>" +
                "我与虎谋早餐");
        songInfoMap.put("574566207",songInfo);

    }


}
